﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class MasDistrictBLL : IMasDistrictBLL
    {
        private static readonly IMasDistrictDAL dal = DataAccess.CreateMasterDistricts();

        private MasDistrictInfo disInfo = new MasDistrictInfo();
        private MasAmphurInfo ampInfo = new MasAmphurInfo();
        private MasProvinceInfo proInfo = new MasProvinceInfo();

        public DataSet LoadDistricts(Nullable<int> Sequence, Nullable<int> Amphur, Nullable<int> Province, string SearchText)
        {
            return dal.LoadDistricts(Sequence, Amphur, Province, SearchText);
        }
        public IList<MasDistrictInfo> ListDistricts()
        {
            return dal.ListDistricts(new MasDistrictInfo(0));
        }
        public IList<MasDistrictInfo> ListDistricts(string Sequence, string Amphur, string Province)
        {
            int disSeq = Sequence.Length > 0 ? Int32.Parse(Sequence) : 0;
            int ampSeq = Amphur.Length > 0 ? Int32.Parse(Amphur) : 0;
            int proSeq = Province.Length > 0 ? Int32.Parse(Province) : 0;

            return dal.ListDistricts(new MasDistrictInfo(disSeq, "", "", new MasAmphurInfo(ampSeq, "", "" , new MasProvinceInfo(proSeq), null, null), null, null));
        }

        public void Insert(string Name, string NameEng, int Amphur, int CreatedBy)
        {
            try
            {
                ampInfo.Sequence = Amphur;
                dal.Insert(new MasDistrictInfo(0, Name, NameEng, ampInfo, CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }        
        }
        public void Update(int Sequence, string Name, string NameEng, int Amphur, int UpdatedBy)
        {
            try
            {
                ampInfo.Sequence = Amphur;
                dal.Update(new MasDistrictInfo(Sequence, Name, NameEng, ampInfo, 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.Update(new MasDistrictInfo(Sequence, "", "", ampInfo, 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
